package com.LachesismStorm.lachesism.commonTools;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @Author lachesism
 * @Date 2024-12-26 17:56
 **/
public class UseNodeScript {
    public static void main(String[] args) {
        try {
            // 使用 ProcessBuilder 调用 Node.js 脚本
            ProcessBuilder builder = new ProcessBuilder("node", "htmlToImage.js");
            builder.directory(new File("/Users/yuno/java/webApp/html-to-image"));  // 设置脚本所在目录
            Process process = builder.start();

            // 获取命令行输出
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);  // 输出日志
            }
            process.waitFor();  // 等待 Node.js 脚本执行完成
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}
